<?php
/*
 * program:	均源
 * author:	雨中漫步 & 上善若水 & qhxin
 * email:	qhxin@qhxin.com
 * date:	2014/11/11
 * description:	又是一年双十一，不能剁手，就写点东西吧~~~~~~
 */

defined('IN_SCHOOL') or die();

/*{TranslateTagBegin}*/
class model_forum extends base_model{

	//hook mod_forum_start.php
	private $table;

	function __construct() {
		//hook mod_forum_init_init_before.php
		parent::__construct();
		$this->table = 'forum';
		//hook mod_forum_init_init_end.php
	}

	public function forum_add($name = '', $display = 0) {
		$id = $this->db->maxid($this->table.'-id', '+1');
		//hook mod_forum_forum_add.php
		return $this->db->set( $this->table.'-id-'.$id, 
					array('id'=>$id, 'name'=> $name ,'display'=>$display));
	}

	public function forum_edit($id , $name = '', $master = '', $display = 0) {
		//hook mod_forum_forum_edit.php
		return $this->db->update( $this->table.'-id-'.$id, 
					array('name'=> $name ,'master'=> $master ,'display'=>$display));
	}
	
	public function forum_edit_tj($id , $add = '+1') {
		$tj = $this->db->count('talks-fid-'.$id, $add );
		//hook mod_forum_forum_edit_tj.php
		return $this->db->update( $this->table.'-id-'.$id, 
					array('tj'=> $tj));
	}
	
	public function forum_get($id) {
		$id = max(0, intval($id));
		//hook mod_forum_forum_get.php
		return $this->db->get($this->table.'-id-'.$id);
	}

	public function forum_delete($id ) {
	
		//hook mod_forum_forum_delete.php
		return $this->db->delete( $this->table.'-id-'.$id);
	}
	
	public function forum_list($display = 1) {
		//hook mod_forum_forum_list.php
		$ret = array();
		
		$cond = $display ? array() : array('display'=>0);
		
		$arr = $this->db->index_fetch($this->table , 'id', $cond, array('id'=>1));
		if(!empty($arr)) {
			foreach($arr as $eacharr) {
				$ret[] = $eacharr;
			}
		}
		return $ret;
	}

	//hook mod_forum_end.php
}
/*{TranslateTagEnd}*/

?>